package com.sisy.demo.config;

import com.sisy.demo.exception.BaseException;
import com.sisy.demo.vo.S2VJSONResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;

/**
 * @Description: 异常处理
 * @author: xx
 * @date: 2020-06-05 16:26
 * @version: 0.0.1
 * @Copyright: 2020 www.jztdata.com Inc. All rights reserved.
 * 注意：本内容仅限于杭州金智塔科技有限公司内部传阅，禁止外泄以及用于其他的商业目
 */
@RestControllerAdvice
public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
    /**
     * 客户端操作异常
     *
     * @param e
     * @return com.jztdata.cl.vo.S2VJSONResult
     * @Author xx
     * @Date 2020-06-05 16:28
     * @throws
     */
    @ExceptionHandler(value = BaseException.class)
    public S2VJSONResult baseHandler(BaseException e) {
        return S2VJSONResult.clientError(e.getMessage());
    }

    /**
     * 服务器异常
     *
     * @param e
     * @return com.jztdata.cl.vo.S2VJSONResult
     * @Author xx
     * @Date 2020-06-05 16:29
     * @throws
     */
    @ExceptionHandler(value = Exception.class)
    public S2VJSONResult allHandler(Exception e) {
        Logger logger = LoggerFactory.getLogger(getClass().getName());
        logger.error("错误",e.getMessage(),e);
        return S2VJSONResult.msg(false, 500, "您的数据或操作有误,请重新检查!");
    }
}
